package JunitTest;

import java.lang.reflect.Field;

public class Reflection {
    public static void main(String[] args) throws Exception {
        Person person = new Person("张三",20);
        Class personClass = person.getClass();
        Field[] fields = personClass.getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            String name = field.getName();
            Class<?> type = field.getType();
            System.out.println("Name:"+name + ",Type: " + type);
            Object value = field.get(person);
            System.out.println("Value: " + value);
        }
    }
}
